using System;
using System.Security;
using System.Web;
using System.Web.Services;
using System.Xml;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2007-MM-DD	
	Status:		release	
	Version:	2.0.0
	Build:		20070709
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/

/*	-----------------------------------------------------------------------	
	Development Notes:
	==================
	20070709:	Starting point. This object has been created to give access
				via a web service to some of the site internals (eg site and
				user profiles)
	-----------------------------------------------------------------------	*/

namespace umlungu.engineX.blogX {
	/// <summary>
	/// umlungu EngineX.BlogX 
	/// This module is a component of the EngineX blogging and content management engine
	/// </summary>
	[WebService(Namespace="http://www.umlungu.com/engineX/")]
	public class siteX : x_result
	{
		#region Invisible properties
		private x_config config;
		private x_siteprofile siteProfile;
		private x_userprofile userProfile;
		#endregion

		#region Constants
		private const string THIS_CONST = "A constant";
		#endregion

		#region Visible properties
		private string property;
		/// <summary>Definiton of the property</summary>
		/// <value>Description of the value of the property</value>
		public string Property {
			get { return property; }
			set { property = value; }
		}
		#endregion

		#region Constructors/Destructors
		/// <summary>Constructor</summary>
		public siteX() : base("blogX") {
			config = new x_config();
			try {
				if (config.SiteProfile == "yes") {
					siteProfile = (x_siteprofile)Application["SiteProfileX"];
				}
				if (config.UserProfile == "yes") {
					userProfile = (x_userprofile)Session["UserProfileX"];
				}
			} 
			catch(x_exception e)		{_AddError(e);}
			catch(SecurityException e) 	{_AddError(e);}
			catch(Exception e) 			{_AddError(e);}
		}
		#endregion

		#region Public methods
		/// <summary>Gets the site profile, ie the application-based profile</summary>
		[WebMethod(Description="Gets the site profile, ie the application-based profile")]
		public XmlDocument GetSiteProfile() {
			try {
				_AddOk(siteProfile.Profile);
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		/// <summary>Gets the user profile, ie the session-based profile</summary>
		[WebMethod(Description = "Gets the user profile, ie the session-based profile")]
		public XmlDocument GetUserProfile() {
			try {
				_AddOk(userProfile.Profile);
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		/// <summary>Gets a field in the site profile</summary>
		[WebMethod(Description = "Gets a field in the site profile")]
		public XmlDocument GetSiteProfileField(string FieldName) {
			try {
				_AddOk(siteProfile.Field(FieldName));
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		/// <summary>Gets a field in the site profile</summary>
		[WebMethod(Description = "Clears a field in the site profile")]
		public XmlDocument ClearSiteProfileField(string FieldName) {
			try {
				siteProfile.Clear(FieldName);
				_AddOk(siteProfile.Field(FieldName));
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		/// <summary>Adds a field to the site profile</summary>
		[WebMethod(Description = "Adds a field to the site profile")]
		public XmlDocument AddSiteProfileField(string FieldName, string FieldValue) {
			try {
				_AddOk(siteProfile.Add(FieldName, FieldValue));
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		/// <summary>Adds an empty field in the the site profile</summary>
		[WebMethod(Description = "Adds an empty field in the the site profile")]
		public XmlDocument AddSiteProfileFieldEmpty(string FieldName) {
			try {
				_AddOk(siteProfile.Add(FieldName));
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		/// <summary>Adds a subobj to a field in the site profile</summary>
		[WebMethod(Description = "Adds a subobj to a field in the site profile")]
		public XmlDocument AddSiteProfileFieldSub(string FieldName) {
			try {
				_AddOk(siteProfile.AddSub(FieldName));
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		/// <summary>Adds a sub object to a field in the site profile</summary>
		[WebMethod(Description = "Adds a sub object to a field in the site profile")]
		public XmlDocument AddSiteProfileFieldSubObj(string FieldName, string SubPrompt, string SubValue) {
			try {
				_AddOk(siteProfile.Add(FieldName, SubPrompt, SubValue));
			}
			catch (x_exception e) { _AddError(e); }
			catch (System.Exception e) { _AddError(e); }
			return (Result);
		}
		#endregion

		#region Protected methods
		/// <summary>
		/// Description of this method
		/// </summary>
		protected void _Example() {
		}
		#endregion

		#region Private methods
		/// <summary>
		/// Description of this method
		/// </summary>
		private void example() {
		}
		#endregion
	}
}
